<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/


Route::group(['middleware' => 'erp.docking'], function () {
    Route::post('/docking', 'DockingController@handle');
});


Route::group(['prefix' => 'common', 'middleware' => 'auth'], function () {
    Route::get('select/customer', 'Common\SelectController@customer');
    Route::get('select/express', 'Common\SelectController@express');
    Route::get('select/callback', 'Common\SelectController@callback');
    Route::get('select/unit', 'Common\SelectController@unit');
    Route::get('select/hsCode', 'Common\SelectController@hsCode');
    Route::get('select/country', 'Common\SelectController@country');
    Route::get('select/currency', 'Common\SelectController@currency');
    Route::get('select/customs', 'Common\SelectController@customs');
    Route::get('select/consumable', 'Common\SelectController@consumable');
    Route::get('select/package', 'Common\SelectController@package');
    Route::get('select/user', 'Common\SelectController@user');
    Route::get('select/{id}/enterprises', 'Common\SelectController@enterprises');

    Route::post('index/upload', 'Common\IndexController@upload');
});


Route::group(
    ['middleware' => 'rbac', 'prefix' => 'customer'],
    function () {

        Route::put('{id}/submit', 'Customer\IndexController@submit')->name('customer.submit');
        Route::put('{id}/reject', 'Customer\IndexController@reject')->name('customer.reject');
        Route::put('{id}/adopt', 'Customer\IndexController@adopt')->name('customer.adopt');
        Route::put('{id}/frozen', 'Customer\IndexController@frozen')->name('customer.frozen');
        Route::put('{id}/unfrozen', 'Customer\IndexController@unfrozen')->name('customer.unfrozen');
        Route::resource('index', 'Customer\IndexController')
            ->name('index', 'customer.index')
            ->name('destroy', 'customer.destroy')
            ->name('edit', 'customer.update')
            ->name('update', 'customer.update')
            ->name('show', 'customer.show')
            ->name('store', 'customer.store');

        Route::resource('address', 'Customer\AddressController')
            ->name('edit', 'address.update')
            ->except(['show', 'destroy']);

        Route::resource('docking', 'Customer\DockingController')
            ->name('edit', 'address.update')
            ->except(['destroy', 'create', 'store', 'show']);

        Route::resource('enterprises', 'Customer\EnterprisesController')
            ->name('edit', 'address.update')
            ->except(['destroy', 'show']);

    }
);


Route::group(
    ['middleware' => 'rbac', 'prefix' => 'system'],
    function () {

        Route::put('express/{id}/status/{status}', 'System\ExpressController@status')->name('express.status');
        Route::resource('express', 'System\ExpressController')
            ->name('edit', 'express.update');

        Route::resource('{id}/express_blacklist', 'System\ExpressBlacklistController');

        Route::resource('dictionary/callback', 'System\Dictionary\CallbackController');

        Route::get('system/{group}', 'System\SystemController@show')->name('system.system');
        Route::put('system/{group}', 'System\SystemController@update')->name('system.system');


        Route::resource('dictionary/customs', 'System\Dictionary\CustomsController')
            ->name('index', 'customs.index')
            ->name('edit', 'customs.update')
            ->name('update', 'customs.update')
            ->name('store', 'customs.store');

        Route::resource('dictionary/currency', 'System\Dictionary\CurrencyController')
            ->name('index', 'currency.index')
            ->name('edit', 'currency.update')
            ->name('update', 'currency.update')
            ->name('store', 'currency.store');

        Route::resource('dictionary/unit', 'System\Dictionary\UnitController')
            ->name('index', 'unit.index')
            ->name('edit', 'unit.update')
            ->name('update', 'unit.update')
            ->name('store', 'unit.store');

        Route::resource('dictionary/hs_code', 'System\Dictionary\HsCodeController')
            ->name('index', 'hs_code.index')
            ->name('edit', 'hs_code.update')
            ->name('update', 'hs_code.update')
            ->name('store', 'hs_code.store');

        Route::resource('dictionary/country', 'System\Dictionary\CountryController')
            ->name('index', 'country.index')
            ->name('edit', 'country.update')
            ->name('update', 'country.update')
            ->name('store', 'country.store');
    }
);


Route::group(
    ['middleware' => 'rbac', 'prefix' => 'product'],
    function () {
        Route::resource('index', 'Product\IndexController')
            ->name('index', 'product.index')
            ->name('edit', 'product.update')
            ->name('update', 'product.update')
            ->name('create', 'product.create')
            ->name('show', 'product.show')
            ->name('destroy', 'product.destroy')
            ->name('store', 'product.store');

        Route::put('index/{id}/review', 'Product\IndexController@review')->name('product.review');
        Route::put('index/{id}/confirm', 'Product\IndexController@confirm')->name('product.confirm');
        Route::put('index/{id}/freeze', 'Product\IndexController@freeze')->name('product.freeze');
        Route::put('index/{id}/reject', 'Product\IndexController@reject')->name('product.reject');
        Route::put('index/{id}/thaw', 'Product\IndexController@thaw')->name('product.thaw');

        Route::get('index/{id}/consumable', 'Product\IndexController@consumable')->name('product.thaw');
        Route::post('index/{id}/consumable', 'Product\IndexController@postConsumable')->name('product.thaw');


        Route::get('inventory', 'Product\InventoryController@index')->name('inventory.index');
        Route::get('book', 'Product\BookController@index')->name('book.index');
        Route::delete('book/{id}', 'Product\BookController@destroy')->name('book.destroy');
        Route::post('book', 'Product\BookController@store')->name('book.store');
    });


Route::group(
    ['middleware' => 'rbac', 'prefix' => 'warehousing'],
    function () {
        Route::resource('index', 'Warehousing\IndexController')
            ->name('index', 'warehousing.index')
            ->name('edit', 'warehousing.update')
            ->name('update', 'warehousing.update')
            ->name('create', 'warehousing.create')
            ->name('show', 'warehousing.show')
            ->name('destroy', 'warehousing.destroy')
            ->name('store', 'warehousing.store');

        Route::put('index/{id}/arrival', 'Warehousing\IndexController@arrival')->name('warehousing.arrival');
        Route::put('index/{id}/review', 'Warehousing\IndexController@review')->name('warehousing.review');
        Route::put('index/{id}/confirm', 'Warehousing\IndexController@confirm')->name('warehousing.confirm');
        Route::put('index/{id}/reject', 'Warehousing\IndexController@reject')->name('warehousing.reject');
        Route::put('index/{id}/compete', 'Warehousing\IndexController@compete')->name('warehousing.compete');
        Route::post('index/{id}/files', 'Warehousing\IndexController@files')->name('warehousing.files');

        Route::put('index/{id}/window-template', 'Warehousing\IndexController@windowTemplate')->name('warehousing.window-template');
        Route::put('index/{id}/window-batch', 'Warehousing\IndexController@windowBatch')->name('warehousing.window-batch');
        Route::put('index/{id}/window-tally', 'Warehousing\IndexController@windowTally')->name('warehousing.window-tally');


        Route::get('tally', 'Warehousing\TallyController@index')->name('tally.index');
        Route::get('tally/{id}', 'Warehousing\TallyController@show')->name('tally.show');
        Route::put('tally/{id}/complete', 'Warehousing\TallyController@complete')->name('tally.complete');
        Route::put('tally/{id}/confirm', 'Warehousing\TallyController@confirm')->name('tally.confirm');
        Route::post('tally/{id}/detail', 'Warehousing\TallyController@storeDetail')->name('tally.storeDetail');
        Route::delete('tally/{id}/detail/{detail}', 'Warehousing\TallyController@destroyDetail')->name('tally.destroyDetail');


        Route::get('shelves', 'Warehousing\ShelvesController@index')->name('shelves.index');
        Route::post('shelves/{id}', 'Warehousing\ShelvesController@shelves')->name('shelves.edit');
        Route::get('shelves/{id}/edit', 'Warehousing\ShelvesController@edit')->name('shelves.edit');

    });

Route::group(
    ['middleware' => 'rbac', 'prefix' => 'warehouse_out'],
    function () {
        Route::resource('index', 'WarehouseOut\IndexController')
            ->name('index', 'warehouse_out.index')
            ->name('edit', 'warehouse_out.update')
            ->name('update', 'warehouse_out.update')
            ->name('create', 'warehouse_out.store')
            ->name('show', 'warehouse_out.show')
            ->name('destroy', 'warehouse_out.destroy')
            ->name('store', 'warehouse_out.store');

        Route::put('index/{id}/review', 'WarehouseOut\IndexController@review')->name('warehouse_out.review');
        Route::put('index/{id}/confirm', 'WarehouseOut\IndexController@confirm')->name('warehouse_out.confirm');
        Route::put('index/{id}/reject', 'WarehouseOut\IndexController@reject')->name('warehouse_out.reject');
        Route::post('index/{id}/files', 'WarehouseOut\IndexController@files')->name('warehouse_out.files');


    });

Route::group(
    ['middleware' => 'rbac', 'prefix' => 'warehouse'],
    function () {
        Route::resource('consumable', 'Warehouse\ConsumableController')
            ->name('index', 'consumable.index')
            ->name('edit', 'consumable.update')
            ->name('update', 'consumable.update')
            ->name('create', 'consumable.store')
            ->name('show', 'consumable.show')
            ->name('store', 'consumable.store');

        Route::post('consumable_stock', 'Warehouse\ConsumableStockController@store')->name('consumable_stock.store');

        Route::resource('package', 'Warehouse\PackageController')
            ->name('index', 'package.index')
            ->name('edit', 'package.update')
            ->name('update', 'package.update')
            ->name('create', 'package.store')
            ->name('show', 'package.show')
            ->name('store', 'package.store');

        Route::post('package_stock', 'Warehouse\PackageStockController@store')->name('package_stock.store');

        Route::get('location', 'Warehouse\LocationController@index')->name('location.index');
        Route::post('location', 'Warehouse\LocationController@store')->name('location.store');
    });


Route::group(
    ['middleware' => 'rbac', 'prefix' => 'order'],
    function () {
        Route::resource('index', 'Order\IndexController')
            ->name('index', 'order.index')
            ->name('edit', 'order.update')
            ->name('update', 'order.update')
            ->name('create', 'order.store')
            ->name('show', 'order.show')
            ->name('store', 'order.store');

        Route::put('index/{id}/confirm', 'Order\IndexController@confirm')->name('order.confirm');
        Route::get('inventory', 'Order\InventoryController@index')->name('order_customer.index');
        Route::get('inventory/{id}', 'Order\InventoryController@show')->name('order_customer.index');
        Route::put('inventory/{id}', 'Order\InventoryController@update')->name('order_customer.update');

        Route::get('shipment', 'Order\ShipmentController@index')->name('order_shipment.index');
        Route::post('shipment/auto', 'Order\ShipmentController@autoStore')->name('order_shipment.store');
        Route::post('shipment/choose', 'Order\ShipmentController@chooseStore')->name('order_shipment.store');
        // 打包
        Route::get('shipment/pack', 'Order\ShipmentController@showPack')->name('order_shipment.index');
        Route::post('shipment/{id}/pack', 'Order\ShipmentController@postPack')->name('order_shipment.index');

        Route::get('picking', 'Order\PickingController@index')->name('picking.index');
        Route::get('picking/{id}', 'Order\PickingController@show')->name('picking.index');
        Route::put('picking/{id}', 'Order\PickingController@update')->name('picking.index');
        Route::put('picking/{id}/picking', 'Order\PickingController@picking')->name('picking.index');
        Route::get('picking/{id}/order', 'Order\PickingController@printForOrder')->name('picking.index');
        Route::get('picking/{id}/location', 'Order\PickingController@printForLocation')->name('picking.index');


        Route::get('shipmentMain', 'Order\ShipmentMainController@index')->name('picking.index');
        Route::post('shipmentMain', 'Order\ShipmentMainController@store')->name('picking.index');
        Route::put('shipmentMain/{id}/checking', 'Order\ShipmentMainController@showCode')->name('picking.index');
        Route::put('shipmentMain/{id}', 'Order\ShipmentMainController@update')->name('picking.index');

    });

